package code1.array;

import java.util.Arrays;
import java.util.List;

/**
 * 原题链接：https://leetcode.cn/problems/binary-search/
 */
public class P704 {

    public static int search(int[] nums, int target) {
        int l=0;
        int r=nums.length-1;
        while(l<r){
            int mid=l+r>>1;
            if(target<=nums[mid]){
                r=mid;
            }else{
                l=mid+1;
            }
        }
        if(nums[l]==target){
            return l;
        }else{
            return -1;
        }
    }

    public static void main(String[] args) {
        int[] arr={-1,0,3,5,9,12};
        int ans=search(arr,2);
        System.out.println(ans);
    }
}
